package com.zxl.yjb.activity.my;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.zxl.yjb.R;
import com.zxl.yjb.base.BaseActivity;
import com.zxl.yjb.bean.CouponBean;
import com.zxl.yjb.http.manager.DataManager;
import com.zxl.yjb.http.observer.ObserverOnNextListener;
import com.zxl.yjb.http.observer.ProgressObserver;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CouponActivity extends BaseActivity {


    @BindView(R.id.iv_back)
    ImageView iv_back;
    @BindView(R.id.tv_page_title)
    TextView tv_page_title;
    @BindView(R.id.tv_order_amount)
    TextView tv_order_amount;
    @BindView(R.id.tv_order_throughout)
    TextView tv_order_throughout;
    @BindView(R.id.tv_order_dec)
    TextView tv_order_dec;
    @BindView(R.id.tv_msg_amount)
    TextView tv_msg_amount;
    @BindView(R.id.tv_msg_throughout)
    TextView tv_msg_throughout;
    @BindView(R.id.tv_msg_dec)
    TextView tv_msg_dec;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coupon);
        ButterKnife.bind(this);
        initView();
        getVoucherList();
    }

    @Override
    protected void initView() {
        tv_page_title.setText("优惠券");

    }



    private void setView(CouponBean couponBean)
    {
        tv_order_amount.setText(couponBean.getVoucher().getOrder_amount());
        tv_order_throughout.setText("订单金额大于"+couponBean.getVoucher_rule().getAction_order_low_throughout()+"元时，");
        tv_order_dec.setText("使用代金券一次"+couponBean.getVoucher_rule().getDec_per_order()+"元");

        tv_msg_amount.setText(couponBean.getVoucher().getTopic_amount());
        tv_msg_throughout.setText("订单金额大于"+couponBean.getVoucher_rule().getAction_topic_low_throughout()+"元时，");
        tv_msg_dec.setText("使用代金券一次"+couponBean.getVoucher_rule().getDec_per_topic()+"元");
    }


    /**
     * 我的优惠券
     * user/voucher_list
     *
     * @param
     */
    private void getVoucherList() {

        DataManager dataManager = new DataManager();
        ObserverOnNextListener<CouponBean> listener = new ObserverOnNextListener<CouponBean>() {
            @Override
            public void onNext(CouponBean couponBean) {
                setView(couponBean);
            }
        };
        dataManager.voucherList(new ProgressObserver<CouponBean>(listener, this));
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }


}
